package com.ruoyi.web.controller.combat.camera;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.poi.excel.ExcelReader;
import com.ruoyi.combat.domain.camera.CombatCameraInfo;
import com.ruoyi.combat.service.camera.ICombatCameraInfoService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.entity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 摄像头信息Controller
 *
 * @author ruoyi
 * @date 2025-01-08
 */
@Api(tags = "课题六：摄像头位置分析-摄像头信息管理")
@RestController
@RequestMapping("/camera/info")
public class CombatCameraInfoController extends BaseController {
    @Autowired
    private ICombatCameraInfoService combatCameraInfoService;

    /**
     * 查询摄像头信息列表
     */
    @ApiOperation(value = "查询摄像头信息列表")
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(CombatCameraInfo combatCameraInfo) {
        startPage();
        List<CombatCameraInfo> list = combatCameraInfoService.selectCombatCameraInfoList(combatCameraInfo);
        return getDataTable(list);
    }

    /**
     * 导出摄像头信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @ApiOperation(value = "导出摄像头信息列表")
    @Log(title = "摄像头信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CombatCameraInfo combatCameraInfo) {
        List<CombatCameraInfo> list = combatCameraInfoService.selectCombatCameraInfoList(combatCameraInfo);
        ExcelUtil<CombatCameraInfo> util = new ExcelUtil<CombatCameraInfo>(CombatCameraInfo.class);
        util.exportExcel(response, list, "摄像头信息数据");
    }
    /**
     * 导入摄像头信息列表
     */
    @ApiOperation(value = "导入摄像头信息列表")
    @Log(title = "摄像头信息", businessType = BusinessType.IMPORT)
    @PostMapping("/imports")
    public AjaxResult imports(MultipartFile file) throws IOException {
        ExcelUtil<CombatCameraInfo> util = new ExcelUtil<CombatCameraInfo>(CombatCameraInfo.class);
        List<CombatCameraInfo> userList = util.importExcel(file.getInputStream());
        String message = combatCameraInfoService.importCombatCameraInfo(userList,false, getUsername());
        return success(message);
    }

    /**
     * 获取摄像头信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @ApiOperation(value = "获取摄像头信息详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(combatCameraInfoService.selectCombatCameraInfoById(id));
    }

    /**
     * 新增摄像头信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @ApiOperation(value = "新增摄像头信息")
    @Log(title = "摄像头信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CombatCameraInfo combatCameraInfo) {
        return toAjax(combatCameraInfoService.insertCombatCameraInfo(combatCameraInfo));
    }

    /**
     * 查询摄像头信息列表
     */
    @ApiOperation(value = "查询摄像头图谱")
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @PostMapping("/graph")
    public AjaxResult getGraph(@RequestBody CombatCameraInfo combatCameraInfo) {
        return success(combatCameraInfoService.getGraphByCameraInfo(combatCameraInfo));
    }
    /**
     * 查询摄像头信息列表
     */
    @ApiOperation(value = "查询摄像头图谱")
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @PostMapping("/graphNew")
    public AjaxResult getGraphNew(@RequestBody(required = false) CombatCameraInfo combatCameraInfo) {
        return success(combatCameraInfoService.getGraphByCameraInfoNew(combatCameraInfo));
    }

    /**
     * 修改摄像头信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "摄像头信息", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改摄像头信息")
    @PutMapping
    public AjaxResult edit(@RequestBody CombatCameraInfo combatCameraInfo) {
        return toAjax(combatCameraInfoService.updateCombatCameraInfo(combatCameraInfo));
    }
    @PostMapping("/edit")
    @Anonymous
    public AjaxResult edit1(@RequestBody CombatCameraInfo combatCameraInfo) {
        return toAjax(combatCameraInfoService.updateCombatCameraInfo(combatCameraInfo));
    }

    /**
     * 删除摄像头信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "摄像头信息", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除摄像头信息")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(combatCameraInfoService.deleteCombatCameraInfoByIds(ids));
    }

    /**
     * 摄像头漏洞类型统计
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "摄像头漏洞类型统计", businessType = BusinessType.DELETE)
    @ApiOperation(value = "摄像头漏洞类型统计")
    @GetMapping("/loopholeType")
    public AjaxResult getloopholeType() {
        return success(combatCameraInfoService.getloopholeType());
    }

    /**
     * 摄像头地区统计
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "摄像头地区统计", businessType = BusinessType.DELETE)
    @ApiOperation(value = "摄像头地区统计")
    @GetMapping("/area")
    public AjaxResult getCameraArea() {
        return success(combatCameraInfoService.getCameraArea());
    }

    @ApiOperation(value = "统计摄像头总数、品牌数")
    @GetMapping("/getCameraNum")
    public AjaxResult getCameraNum() {
        return success(combatCameraInfoService.getCameraNum());
    }
    @ApiOperation(value = "统计摄像头定位")
    @GetMapping("/getCameraAddress")
    public AjaxResult getCameraAddress(@RequestParam("id") Long id) {
        return success(combatCameraInfoService.getCameraAddress(id));
    }


    /**
     * 摄像头品牌统计
     */
    @ApiOperation(value = "摄像头品牌统计")
    @GetMapping("/brand")
    public AjaxResult getCameraBrand() {
        return success(combatCameraInfoService.getCameraBrand());
    }




}
